// 属性访问控制
// 还可以实现属性装饰器来进行访问控制或着设置初始值
function defaultValue(value:any){
    return function(target,propertyKey){
        let val = value;
        const getter = function(){
            return val;
        }
        const setter = function(newValue){
            val = newValue
        }
        // ES2021
        Object.defineProperty(target,propertyKey,{
            enumerable:true,
            configurable:true,
            get:getter,
            set:setter
        })
    }
}
class Settings{
    @defaultValue('dark')
    theme:string;
    @defaultValue(1000 * 10)
    timeout:number;
}
const setting = new Settings();
console.log(setting.theme);
console.log(setting.timeout);
setting.theme = 'light';
console.log(setting.theme);
